import {
  createRouter,
  createWebHistory,
  RouterOptions,
  RouteRecordRaw,
} from 'vue-router'
import Layout from '@/components/layout/layout.vue'
import { menuRoutes } from './menu'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: Layout,
    redirect: '/pro-components',
    children: [...menuRoutes],
  },
]

const routerOptions: RouterOptions = {
  history: createWebHistory(),
  routes, // `routes: routes` 的缩写
}

const router = createRouter(routerOptions)

router.beforeEach((to, _, next) => {
  document.title = (to.meta?.title as string) || 'Vite + Vue 3 + TS'
  next()
})

export default router
